#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSplitter>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
   // QSplitter* hSplitter = new QSplitter(Qt::Horizontal);//水平（左右）类型
    on_pushButton_add_clicked();
}

MainWindow::~MainWindow()
{
    delete ui;
}

#include "projectitem.h"
#include <QUuid>
void MainWindow::on_pushButton_add_clicked()
{
    QString id = QUuid::createUuid().toString();
    if(sceneProjectMap.keys().contains(id))
        return;
    ProjectItem *item = new ProjectItem(id,ui->scrollAreaWidgetContents);
    sceneProjectMap.insert(id,item);                                  //数据新增
    ui->verticalLayout->insertWidget(sceneProjectMap.size()-1,item);  //新增目录
    ui->stackedWidget->addWidget(item->getScene());                 //新增操作界面
    ui->stackedWidget->setCurrentWidget(item->getScene());          //显示操作界面
    connect(item,&ProjectItem::clickThis,this,[=](QString id)         //点击目录，显示操作界面
    {
        if(sceneProjectMap.keys().contains(id))
        {
           int index = ui->stackedWidget->indexOf(sceneProjectMap[id]->getScene());
           ui->stackedWidget->setCurrentIndex(index);
        }
    });
    connect(item,&ProjectItem::deleteThis,this,[=](QString id)        //删除操作
    {
        if(sceneProjectMap.keys().contains(id))
        {
            ui->stackedWidget->removeWidget(sceneProjectMap[id]->getScene());
            delete sceneProjectMap[id];
            sceneProjectMap.remove(id);
        }
    });
}

void MainWindow::on_pushButton_min_clicked()
{
    if(ui->scrollArea->isHidden())
        ui->scrollArea->show();
    else
        ui->scrollArea->hide();
}
